//
//  PersonReplenishingView.m
//  MobileShoppingMall
//
//  Created by Mac on 2021/5/25.
//  Copyright © 2021 张璞. All rights reserved.
//

#import "PersonReplenishingView.h"

@interface PersonReplenishingView()<UIGestureRecognizerDelegate>

@property (nonatomic,strong) UILabel *titleLB;

@property (nonatomic,strong) UIView *bgView;

@end

@implementation PersonReplenishingView

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        [self initUI];
    }
    return self;
}
#pragma mark - UI
-(void)initUI{
    [self addSubview:self.titleLB];
    [self addSubview:self.bgView];
    
    NSArray *arr = @[@"充值话费"];
    for (int i = 0; i<arr.count; i++) {
        int x = i%5;
        int y = i/5;
        NSString *imageName = [NSString stringWithFormat:@"个人中心_%@",arr[i]];
        UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(23+x*(24+(ScreenWidth-120-46-10)/4), 26 + y * 60, 24, 24)];
        img.image = LoadImage(imageName);
        [self.bgView addSubview:img];
        
        UILabel *lb = [[UILabel alloc] initWithFrame:CGRectMake(img.left-15, img.bottom+5, img.width+30, 18)];
        lb.textAlignment = NSTextAlignmentCenter;
        lb.font = FontSet(13);
        lb.text = arr[i];
        lb.textColor = MainBlackTextColor;
        [self.bgView addSubview:lb];
        
        UIView *touchView = [[UIView alloc] initWithFrame:CGRectMake(x*((ScreenWidth-20)/5),26 + y * 60, (ScreenWidth-20)/5, 50)];
        touchView.backgroundColor = Color_Clear;
        touchView.tag = i;
        touchView.userInteractionEnabled = YES;
        [self.bgView addSubview:touchView];
        
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(touchClick:)];
        tap.delegate = self;
        [touchView addGestureRecognizer:tap];
    }
}
#pragma mark - lazy
- (UILabel *)titleLB{
    if (!_titleLB) {
        _titleLB = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 100, 25)];
        _titleLB.textColor = MainBlackTextColor;
        _titleLB.font = FontSetWithWeight(18, 0.3f);
        _titleLB.text = @"更多";
    }
    return _titleLB;
}
- (UIView *)bgView{
    if (!_bgView) {
        _bgView = [[UIView alloc] initWithFrame:CGRectMake(10, self.titleLB.bottom+10, ScreenWidth-20, 100)];
        _bgView.backgroundColor = UIColor.whiteColor;
        _bgView.clipsToBounds = YES;
        _bgView.layer.cornerRadius = 4;
    }
    return _bgView;
}
#pragma mark - SEL
-(void)touchClick:(UIGestureRecognizer *)tap{
    UIView *view = (UIView *)tap.view;
    NSInteger index = (NSInteger)view.tag;
    if (self.touchBlock) {
        self.touchBlock(index);
    }
}



@end


